/* eslint-disable */
<template>
  <div class="FinancialIndicators" chief-style-set>
    <Title title='经营业绩（财务指标）' more :MoreUrl='MoreJump(this, "OperatingCondition", 1)'></Title>
    <div class="content-h-auto" chief-style-set>
      <Charts :pChartsOption='ChartsOption'></Charts>
    </div>
  </div>
</template>

<script>
import Title from "@/components/baseTitle";
import Charts from "@/components/portalEcharts/BarEcharts";
import { getCw } from "@/api/portalChief";
import { MoreJump } from "@/util/util";
export default {
  name: "FinancialIndicators",
  components: {
    Title, Charts
  },
  data () {
    return {
      ChartsOption: {},
      MoreJump
    };
  },
  created () {
    getCw(this.$store.state.user.project.projectNo).then(res => {
      this.disposeData(res);
    });
  },
  methods: {
    // eslint-disable-next-line valid-jsdoc
    /**
    * 方法描述描述
    * @param {Object} res 参数作用
    */
    disposeData (res) {
      if (res.status === 200) {
        this.ChartsOption = {
          xAxisNameList: ["本月", "本年", "本月 ", "本年 "],
          xAxisSecond: {
            data: ["原煤产量", "销售量"],
            position: "bottom",
            offset: 15,
            axisLine: {
              show: false
            },
            axisTick: {
              show: false
            }
          },
          BarList: [
          ]
        };
        let list = res.data.data;
        let cloneList = [];
        let outputList = [
          { name: "目标", data: [], barWidth: 20 },
          { name: "实际", data: [], barWidth: 20 },
          { name: "同期", data: [], barWidth: 20, color: "#9BBB58" }
        ];
        if (Object.keys(list).length > 0) {
          this.ChartsOption.xAxisSecond.data = Object.keys(list);
          Object.values(list).forEach((item, index) => {
            cloneList.push(...Object.values(item));
          });
          cloneList.forEach((item, index) => {
            cloneList[index] = Object.values(item);
          });
          outputList.forEach((item, i) => {
            cloneList.forEach((citem, index) => {
              if (outputList[i].name === "目标") {
                outputList[i].data.push(citem[0]);
              }
              if (outputList[i].name === "实际") {
                outputList[i].data.push(citem[2]);
              }
              if (outputList[i].name === "同期") {
                outputList[i].data.push(citem[1]);
              }
            });
          });
          this.ChartsOption.BarList = outputList;
        } else {
          this.ChartsOption = {};
        }
      } else {
        this.ChartsOption = {};
      }
    }
  }
};
</script>